/*
 * Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "ohos_init.h"
#include "cmsis_os2.h"
#include "wifi_connect.h"
#include "lcd_st7789.h"
#include "lv_port_disp.h"
#include "lvgl.h"

// 配置wifi账号密码
#define CONFIG_WIFI_SSID "Huawei"
#define CONFIG_WIFI_PWD "12345678"

osEventFlagsId_t evt_id; // event flags id

extern void app_background_task(void);
extern int  app_time_task(void);
extern void app_weather_task(void);
extern void app_sensor_task(void);

static void APP_TaskCreate(void)
{
    osThreadAttr_t attr;
    attr.name = "app_background_task";
    attr.attr_bits = 0U;
    attr.cb_mem = NULL;
    attr.cb_size = 0U;
    attr.stack_mem = NULL;
    attr.stack_size = 1024 * 8;
    attr.priority = 25;

    //创建背景显示任务 

    
    //创建时间数据获取并显示任务

    
    //创建天气数据获取并显示任务

    
    //创建传感器数据采集并显示任务


    evt_id = osEventFlagsNew(NULL);
    if (evt_id == NULL)
    {
    printf("Falied to create EventFlags!\n");
    }
}

static void app_main_task(void)
{
    lv_init();              // 初始化lvgl
    lv_port_disp_init();    // 显示初始化

    WifiConnect(CONFIG_WIFI_SSID, CONFIG_WIFI_PWD);

    APP_TaskCreate();

    while(1){
        lv_tick_inc(2);
        lv_task_handler();  // 循环调用处理lvgl tasks
        usleep(10);
    }
}

static void ExampleEntry(void)
{
    osThreadAttr_t attr;

    attr.name = "app_main_task";
    attr.attr_bits = 0U;
    attr.cb_mem = NULL;
    attr.cb_size = 0U;
    attr.stack_mem = NULL;
    attr.stack_size = 1024 * 8;
    attr.priority = 25;

    if (osThreadNew((osThreadFunc_t)app_main_task, NULL, &attr) == NULL)
    {
        printf("Falied to create app_main_task!\n");
    }

}

APP_FEATURE_INIT(ExampleEntry);